
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RequestARoom.java
 *
 * Created on Dec 15, 2011, 3:14:06 PM
 */

/**
 *
 * @author dabeast23
 */
public class RequestARoom extends javax.swing.JFrame {

    /** Creates new form RequestARoom */
    public RequestARoom(ArrayList reservationList) {
        setResizable(false);
	setTitle("Hotel Kiosk: Request A Room");
	setDefaultCloseOperation(this.EXIT_ON_CLOSE);
        initComponents();
        this.reservationList = reservationList;
        model = (DefaultTableModel)roomTable.getModel();
        this.setLocationRelativeTo(null);
        roomList = rooms();
        updateTable(roomList);
    }
    public RequestARoom() {
        setResizable(false);
	setTitle("Hotel Kiosk: Request A Room");
	setDefaultCloseOperation(this.EXIT_ON_CLOSE);
        initComponents();
        this.reservationList = reservationList;
        model = (DefaultTableModel)roomTable.getModel();
        this.setLocationRelativeTo(null);
        roomList = rooms();
        updateTable(roomList);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        backgroundPanel = new javax.swing.JPanel();
        roomRequestLabel = new javax.swing.JLabel();
        backButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        roomTable = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        backgroundPanel.setBackground(new java.awt.Color(102, 0, 0));

        roomRequestLabel.setFont(new java.awt.Font("Tahoma", 1, 24));
        roomRequestLabel.setForeground(new java.awt.Color(255, 255, 204));
        roomRequestLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        roomRequestLabel.setText("Room Request");

        backButton.setBackground(new java.awt.Color(255, 255, 204));
        backButton.setFont(new java.awt.Font("Comic Sans MS", 0, 11));
        backButton.setForeground(new java.awt.Color(255, 255, 255));
        backButton.setText("Back");
        backButton.setContentAreaFilled(false);
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });

        roomTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Room", "Style", "Price"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        roomTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                roomTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(roomTable);
        roomTable.getColumnModel().getColumn(0).setResizable(false);
        roomTable.getColumnModel().getColumn(1).setResizable(false);
        roomTable.getColumnModel().getColumn(2).setResizable(false);

        javax.swing.GroupLayout backgroundPanelLayout = new javax.swing.GroupLayout(backgroundPanel);
        backgroundPanel.setLayout(backgroundPanelLayout);
        backgroundPanelLayout.setHorizontalGroup(
            backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundPanelLayout.createSequentialGroup()
                .addGap(63, 63, 63)
                .addComponent(roomRequestLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
                .addGap(65, 65, 65))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundPanelLayout.createSequentialGroup()
                .addContainerGap(333, Short.MAX_VALUE)
                .addComponent(backButton)
                .addContainerGap())
            .addGroup(backgroundPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                .addContainerGap())
        );
        backgroundPanelLayout.setVerticalGroup(
            backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundPanelLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(roomRequestLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(backButton)
                .addGap(11, 11, 11))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        ProspectiveGuest PG = new ProspectiveGuest(reservationList);
        PG.setVisible(true);
        this.setVisible(false);
}//GEN-LAST:event_backButtonActionPerformed

    private void roomTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_roomTableMouseClicked
        int rowNum = roomTable.convertRowIndexToModel(roomTable.getSelectedRow());

        if (evt.getClickCount() ==2)
        {
                RoomRequestForm RRF = new RoomRequestForm(this, true, rowNum,reservationList);
                RRF.setVisible(true);
                this.setVisible(false);
        }
        else
        {
            return;
        }
    }//GEN-LAST:event_roomTableMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                RequestARoom dialog = new RequestARoom();
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backButton;
    private javax.swing.JPanel backgroundPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel roomRequestLabel;
    private javax.swing.JTable roomTable;
    // End of variables declaration//GEN-END:variables
    private DefaultTableModel model;
    private ArrayList <Room> roomList;
    private ArrayList <Reservation> reservationList;

    private ArrayList rooms()
    {
        ArrayList<Room> list = new ArrayList();
        Room room1 = new Room("100", 200.00, 1);
        list.add(room1);
        Room room2 = new Room("101", 200.00, 1);
        list.add(room2);
        Room room3 = new Room("102", 200.00, 1);
        list.add(room3);
        Room room4 = new Room("103", 320.00, 2);
        list.add(room4);
        Room room5 = new Room("104", 320.00, 1);
        list.add(room5);
        Room room6 = new Room("105", 320.00, 2);
        list.add(room6);
        Room room7 = new Room("106", 320.00, 1);
        list.add(room7);
        Room room8 = new Room("107", 200.00, 2);
        list.add(room8);
        Room room9 = new Room("108", 200.00, 1);
        list.add(room9);
        Room room10 = new Room("109", 200.00, 1);
        list.add(room10);
        Room room11 = new Room("110", 320.00, 1);
        list.add(room11);
        Room room12 = new Room("111", 320.00, 2);
        list.add(room12);
        Room room13 = new Room("112", 320.00, 1);
        list.add(room13);
        Room room14 = new Room("113", 320.00, 2);
        list.add(room14);
        Room room15 = new Room("114", 400.00, 1);
        list.add(room15);


        return list;
    }

    private void clearTable()
    {
            for(int i = roomTable.getRowCount()-1;i>=0;i--)
            {
                if (model.getRowCount()>0)
                    model.removeRow(i);
            }

    }

    private void updateTable(ArrayList<Room> listToAdd)
    {
        clearTable();

        for(int i=0;i<listToAdd.size();i++)
        {
            String room =listToAdd.get(i).getName();
            String numBeds = Integer.toString(listToAdd.get(i).getNumBeds()) + " bed(s)";
            String price = Double.toString(listToAdd.get(i).getCost());

            model.insertRow(i,new Object[]{room,numBeds,price});
        }
    }
}
